//  import App from '../App.vue'
// import LoginApp from '../views/LoginApp.vue'
//  import halo from '../views/halo.vue'
// import { createRouter, createWebHistory } from 'vue-router'

// const routes = [
//   {
//     path: '/LoginApp',
//     name: 'LoginApp',
//     component: LoginApp
//   },
//   {
//     path: '/demo',
//     name: 'demo',
//     component: App
//   },
//   {
//     path: '/halo',
//     name: 'halo',
//     component: halo
//   }
// ]

// const router = createRouter({
//   history: createWebHistory(process.env.BASE_URL),
//   routes
// })

// export default router    
import App from '../App.vue'
import LinginX from '../views/Lingin-x.vue'
import LoginApp from '../views/LoginApp.vue'
import halo from '../views/halo.vue'
import doubaochat from '../views/doubaochat.vue'
import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  
  {
    path: '/Lingin-x',
    name: 'LinginX',
    component: LinginX
  },
  {
    path: '/doubaochat',
    name: 'doubaochat',
    component: doubaochat
  },
  {
    path: '/LoginApp',
    name: 'LoginApp',
    component: LoginApp
  },
  {
    path: '/demo',
    name: 'demo',
    component: App
  },
  {
    path: '/halo',
    name: 'halo',
    component: halo
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

router.beforeEach((to, from, next) => {
    const isAuthenticated = sessionStorage.getItem('showLogin') === '0'
    // 判断目标路由是否为 /LoginDouBao
    if (to.path === '/LoginApp') {
        next() // 直接放行
    } else if (!isAuthenticated) {
        next({ path: '/LoginApp' }) 
    } else {
        next()
    }
})


export default router